Guard Deformable DETR and LW-DETR Hungarian matchers against infinite cost matrices#47066
Open
MutugiD wants to merge 1 commit into
Open
Guard Deformable DETR and LW-DETR Hungarian matchers against infinite cost matrices#47066MutugiD wants to merge 1 commit into
MutugiD wants to merge 1 commit into
Conversation
… cost matrices Under AMP/fp16, the sigmoid focal classification cost can overflow to inf/NaN, which makes scipy's linear_sum_assignment raise "ValueError: cost matrix is infeasible". Replace non-finite costs with torch.finfo(dtype).max before matching, matching the RT-DETR fix in huggingface#47016. Adds regression tests for both matchers. Fixes huggingface#47065.
Contributor
|
[For maintainers] Suggested jobs to run (before merge) run-slow: deformable_detr, lw_detr |
Contributor
CI recapDashboard: View test results in Grafana |
Author
|
The This is the This PR only touches the two loss matchers and their tests — the |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What does this PR do?
Fixes #47065. Two more Hungarian matchers share the non-finite-cost crash first reported for RT-DETR in #47000 and still carry the unguarded
scipy.optimize.linear_sum_assignment(cost_matrix)pattern onmain:DeformableDetrHungarianMatcherinsrc/transformers/loss/loss_deformable_detr.pyLwDetrHungarianMatcherinsrc/transformers/loss/loss_lw_detr.pyBoth use the sigmoid focal classification cost, which can overflow to
inf/NaNunder AMP/fp16;linear_sum_assignmentthen raisesValueError: cost matrix is infeasible. This PR replaces non-finite costs withtorch.finfo(cost_matrix.dtype).maxbefore matching, following @guarin's recommendation in #47000 and matching the RT-DETR fix in #47016:This completes the sweep started in #47048 (DETR + Grounding DINO) across the remaining DETR-family loss matchers.
Tests
Adds a CPU-only regression test for each matcher:
tests/models/deformable_detr/test_modeling_deformable_detr.py::DeformableDetrHungarianMatcherInfeasibleCostTesttests/models/lw_detr/test_modeling_lw_detr.py::LwDetrHungarianMatcherInfeasibleCostTestEach feeds a non-finite cost (a
NaNlogit and aninfbox coordinate) through the matcher and asserts it no longer raises and returns correctly-sized assignments. Both fail onmain(with theValueError) and pass with the guard.Before submitting
Who can review?
@guarin @yonigozlan